﻿namespace LinqToSqlQueryVisualizer
{
    using Microsoft.VisualStudio.DebuggerVisualizers;

    /// <summary>
    /// The class that is supposed to define the visualizer UI / behavior
    /// Its implementation delegates this to a provider specific query visualizer.
    /// </summary>
    public class DialogChooser : DialogDebuggerVisualizer
    {
        public static void TestShow(object elementToVisualize)
        {
            var visualizerHost = new VisualizerDevelopmentHost(elementToVisualize, typeof(DialogChooser), typeof(SourceChooser));
            visualizerHost.ShowVisualizer();
        }

        /// <summary>
        /// The format of the query information and the desired UI will usually depend on the Linq to SQLq provider
        /// used by the query. 
        /// Therefore in this general query visualizer we only read the assembly and class for the specific
        /// query visualizer from the Stream and call the method "Display" on this class, which in turn will
        /// read the query information and show the UI.         
        /// </summary>
        /// <param name="windowService">Used to display the UI.</param>
        /// <param name="objectProvider">Used to retrieve the data (as Stream) from the visualizer proxy.</param>
        protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider)
        {
            var rawStream = objectProvider.GetData();

            Visualizer.Display(windowService, rawStream);
        }
    }
}